#include "BasicClass.h"

void Monster::LevelUp()
{   /*技能选择*/
    have_skill[0].skill;
    //还没有制作图形界面，先CIN

    /*基础属性*/
    this->level += 1;
    this->HP += ceil(this->normal_HP * 0.1) + 1;
    this->Attack += ceil(this->normal_Attack * 0.1) + 1;
    this->Defense += ceil(this->normal_Defense * 0.1) + 1;
    this->Speed += ceil(this->normal_Speed * 0.1) + 1;
    cout << this->name << "升级了！" << "现在是" << this->level << "级" << endl;
}



void Monster::debugSee()
{
    cout << "Monster::debugSee()" << endl;
    cout << "name: " << this->name << endl;
    cout << "type: " << this->type << endl;
    cout << "xp: " << this->xp << endl;
    cout << "level: " << this->level << endl;
    cout << "normal_HP: " << this->normal_HP << endl;
    cout << "normal_Attack: " << this->normal_Attack << endl;
    cout << "normal_Defense: " << this->normal_Defense << endl;
    cout << "normal_Speed: " << this->normal_Speed << endl;
    cout << "HP: " << this->HP << endl;
    cout << "Attack: " << this->Attack << endl;
    cout << "Defense: " << this->Defense << endl;
    cout << "Speed: " << this->Speed << endl;
    cout << "isAlive: " << this->isAlive << endl;
}

/*怪物大类*/
/*怪物生成构造函数*/
void Monster::Creat(string name, ElementType type, int normal_HP, int normal_Attack, int normal_Defense, int normal_Speed, int xp, int level) {
    this->name = name;
    this->type = type;
    this->xp = xp;
    this->level = level;
    this->normal_HP = normal_HP;
    this->normal_Attack = normal_Attack;
    this->normal_Defense = normal_Defense;
    this->normal_Speed = normal_Speed;
    /*开局满状态*/
    this->HP = normal_HP;
    this->Attack = normal_Attack;
    this->Defense = normal_Defense;
    this->Speed = normal_Speed;
    this->isAlive = true;
    /*一些危险初始化，注意一定要重新初始化*/
    this->enemy = NULL;
    this->Condiction = { 0 };
    this->have_skill->skill = NULL;
    this->have_skill->MP_now = 0;
    this->have_skill->cold_time = 0;
    cout << name << "已经构造" << endl;
}
/*满状态复活*/
void Monster::Revive() {
    this->HP = this->normal_HP;
    this->Attack = this->normal_Attack;
    this->Defense = this->normal_Defense;
    this->Speed = this->normal_Speed;
    this->Condiction = { 0 };
    this->isAlive = true;
    /*技能也要初始化*/
    for (int i = 0; i < 4; i++) {
        this->have_skill[i].cold_time = 0;
        this->have_skill[i].MP_max = 10;
        this->have_skill[i].MP_now = this->have_skill[0].MP_max;//一定要改
    }
    cout << this->name << "已经复活" << endl;
}
/*显示怪物信息（待实现）*/
void Monster::ShowInfo() {
    //此处等待包一箱
}
/*受击函数*/
void Monster::Hurt(int damage) {
    /*受伤公式*/
    int real_damage = damage - this->Defense;
    if (real_damage < 0) {
        real_damage = 0;
        cout << this->name << "感觉在挠痒痒" << endl;
    }
    this->HP -= real_damage;
    cout << this->name << "受到" << real_damage << "点伤害" << endl;
    if (this->HP <= 0) {
        this->isAlive = false;
        cout << this->name << "死了" << endl;
    }
}
/*延时持续性技能效果函数*/
void Monster::EffectList()
{
    for (int i = 0; i < 10; i++) {
        if (this->myeffect[i] != NULL) {
            this->myeffect[i](this, enemy);
        }
    }
}

/*发动技能函数*/
void Monster::SkillUse(int skill_id) {
    //有点麻烦的函数，用函数指针吗？
    cout << have_skill[skill_id].skill->skill_name << endl;
    cout << have_skill[skill_id].MP_now << endl;

    /*技能逻辑：绘制UI->点击按钮->判断条件->按钮使用该函数->技能指针->技能效果函数指针+通常效果*/
    if (have_skill[skill_id].MP_now >= have_skill[skill_id].skill->skill_cost_MP \
        && have_skill[skill_id].cold_time == 0) {
        //如果MP足够
        have_skill[skill_id].skill->Use(this, enemy);
        have_skill[skill_id].MP_now -= have_skill[skill_id].skill->skill_cost_MP;
        have_skill[skill_id].cold_time = have_skill[skill_id].skill->skill_cold;
        cout << this->name << "使用了 " << have_skill[skill_id].skill->skill_name << " " << endl;
    }
    else {
        cout << this->name << "没有足够的MP" << endl;
    }
}

class Bulbasaur : public Monster {
public:
    Bulbasaur(int level = 1) {
        Creat("妙蛙种子", Grass, 450, 49, 49, 45, 0, level);
        // 初始化技能
        have_skill[0].skill = &vineWhip;
        have_skill[0].MP_max = 20;
        have_skill[0].MP_now = 20;

        have_skill[1].skill = &tackle;
        have_skill[1].MP_max = 30;
        have_skill[1].MP_now = 30;

        have_skill[2].skill = &growl;
        have_skill[2].MP_max = 15;
        have_skill[2].MP_now = 15;

        have_skill[3].skill = &poisonPowder;
        have_skill[3].MP_max = 10;
        have_skill[3].MP_now = 10;
    }
};

class Charmander : public Monster {
public:
    Charmander(int level = 1) {
        Creat("小火龙", Fire, 390, 52, 43, 65, 0, level);
        // 初始化技能
        have_skill[0].skill = &ember;
        have_skill[0].MP_max = 20;
        have_skill[0].MP_now = 20;

        have_skill[1].skill = &scratch;
        have_skill[1].MP_max = 30;
        have_skill[1].MP_now = 30;

        have_skill[2].skill = &growl;
        have_skill[2].MP_max = 15;
        have_skill[2].MP_now = 15;

        have_skill[3].skill = &smokescreen;
        have_skill[3].MP_max = 10;
        have_skill[3].MP_now = 10;
    }
};

class Squirtle : public Monster {
public:
    Squirtle(int level = 1) {
        Creat("杰尼龟", Water, 440, 48, 65, 43, 0, level);
        // 初始化技能
        have_skill[0].skill = &waterGun;
        have_skill[0].MP_max = 20;
        have_skill[0].MP_now = 20;

        have_skill[1].skill = &tackle;
        have_skill[1].MP_max = 30;
        have_skill[1].MP_now = 30;

        have_skill[2].skill = &tailWhip;
        have_skill[2].MP_max = 15;
        have_skill[2].MP_now = 15;

        have_skill[3].skill = &withdraw;
        have_skill[3].MP_max = 10;
        have_skill[3].MP_now = 10;
    }
    void evolution() {
        Creat("水箭龟", Water, normal_HP + 10, normal_HP + 2, normal_Defense + 2, normal_Speed + 2, xp, level);
        have_skill[0].skill = &hydroPump;
        have_skill[0].MP_max = 15;
        have_skill[0].MP_now = 15;

        have_skill[1].skill = &skullBash;
        have_skill[1].MP_max = 10;
        have_skill[1].MP_now = 10;

        have_skill[2].skill = &rapidSpin;
        have_skill[2].MP_max = 20;
        have_skill[2].MP_now = 20;

        have_skill[3].skill = &rainDance;
        have_skill[3].MP_max = 8;
        have_skill[3].MP_now = 8;
    }
};

// 效果函数
void PoisonEffect(Monster* source, Monster* target) {
    target->Condiction.poison = 1;
    cout << target->name << "中毒了！" << endl;
}

void BurnEffect(Monster* source, Monster* target) {
    target->Condiction.burn = 1;
    cout << target->name << "烧伤了！" << endl;
}

void RainEffect(Monster* source, Monster* target) {
    if (target->type == Fire) target->Attack -= 2;
    source->Attack += 2;
    cout << "开始下雨了！水系技能增强，火系技能减弱！" << endl;
}

void AccuracyDownEffect(Monster* source, Monster* target) {
    cout << target->name << "的命中率下降了！" << endl;
}

void DefenseUpEffect(Monster* source, Monster* target) {
    target->Defense += 2;
    cout << target->name << "的防御力提高了！" << endl;
}

Skill vineWhip, tackle, growl, poisonPowder;
Skill ember, scratch, smokescreen;
Skill waterGun, tailWhip, withdraw;
Skill hydroPump, skullBash, rapidSpin, rainDance;

// 初始化技能
void InitSkills() {
    vineWhip.Creat("藤鞭", 40, 0, 5, Grass, nullptr);
    tackle.Creat("撞击", 35, 0, 3, Normal, nullptr);
    growl.Creat("叫声", 0, 2, 2, Normal, nullptr); 
    poisonPowder.Creat("毒粉", 0, 3, 4, Normal, PoisonEffect);

    ember.Creat("火花", 40, 0, 5, Fire, BurnEffect);
    scratch.Creat("抓", 40, 0, 3, Normal, nullptr);
    smokescreen.Creat("烟雾", 0, 2, 3, Normal, AccuracyDownEffect);

    waterGun.Creat("水枪", 40, 0, 5, Water, nullptr);
    tailWhip.Creat("摇尾巴", 0, 2, 2, Normal, nullptr);
    withdraw.Creat("缩入壳中", 0, 2, 3, Water, DefenseUpEffect);

    hydroPump.Creat("水炮", 110, 2, 8, Water, nullptr);  // 高威力水系技能
    skullBash.Creat("火箭头槌", 130, 3, 10, Normal, DefenseUpEffect);  // 蓄力攻击，同时提升防御
    rapidSpin.Creat("高速旋转", 20, 0, 5, Water, nullptr);  // 解除束缚效果
    rainDance.Creat("求雨", 0, 5, 5, Water, RainEffect);  // 改变天气
}
